home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / objects.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  25.8 KB  |  870 lines

  1. /* Generic Objects and Functions.
  2.    Copyright (C) 1995 Amdahl Corporation.
  3.    Copyright (C) 1995 Board of Trustees, University of Illinois
  4.    Copyright (C) 1995 Ben Wing
  5.  
  6. This file is part of XEmacs.
  7.  
  8. XEmacs is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with XEmacs; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include <config.h>
  23. #include "lisp.h"
  24.  
  25. #include "device.h"
  26. #include "elhash.h"
  27. #include "faces.h"
  28. #include "frame.h"
  29. #include "objects.h"
  30. #include "specifier.h"
  31. #include "window.h"
  32.  
  33. /* Authors: Ben Wing, Chuck Thompson */
  34.  
  35. void
  36. finalose (void *ptr)
  37. {
  38.   Lisp_Object obj; 
  39.   XSETOBJ (obj, Lisp_Record, ptr);
  40.  
  41.   signal_simple_error
  42.     ("Can't dump an emacs containing window system objects", obj);
  43. }
  44.  
  45.  
  46. /****************************************************************************
  47.  *                       Color-Instance Object                              *
  48.  ****************************************************************************/
  49.  
  50. Lisp_Object Qcolor_instancep;
  51. static Lisp_Object mark_color_instance (Lisp_Object, void (*) (Lisp_Object));
  52. static void print_color_instance (Lisp_Object, Lisp_Object, int);
  53. static void finalize_color_instance (void *, int);
  54. static int color_instance_equal (Lisp_Object, Lisp_Object, int depth);
  55. static unsigned long color_instance_hash (Lisp_Object obj, int depth);
  56. DEFINE_LRECORD_IMPLEMENTATION ("color-instance", color_instance,
  57.                    mark_color_instance, print_color_instance,
  58.                    finalize_color_instance, color_instance_equal,
  59.                    color_instance_hash,
  60.                    struct Lisp_Color_Instance);
  61.  
  62. static Lisp_Object
  63. mark_color_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
  64. {
  65.   struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
  66.   ((markobj) (c->name));
  67.   MAYBE_DEVMETH (XDEVICE (c->device), mark_color_instance, (c, markobj));
  68.  
  69.   return (c->device);
  70. }
  71.  
  72. static void
  73. print_color_instance (Lisp_Object obj, Lisp_Object printcharfun,
  74.               int escapeflag)
  75. {
  76.   char buf[100];
  77.   struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
  78.   if (print_readably)
  79.     error ("printing unreadable object #<color-instance 0x%x>",
  80.            c->header.uid);
  81.   write_c_string ("#<color-instance ", printcharfun);
  82.   print_internal (c->name, printcharfun, 0);
  83.   write_c_string (" on ", printcharfun);
  84.   print_internal (c->device, printcharfun, 0);
  85.   MAYBE_DEVMETH (XDEVICE (c->device), print_color_instance,
  86.          (c, printcharfun, escapeflag));
  87.   sprintf (buf, " 0x%x>", c->header.uid);
  88.   write_c_string (buf, printcharfun);
  89. }
  90.  
  91. static void
  92. finalize_color_instance (void *header, int for_disksave)
  93. {
  94.   struct Lisp_Color_Instance *c = (struct Lisp_Color_Instance *) header;
  95.  
  96.   if (for_disksave) finalose (c);
  97.  
  98.   MAYBE_DEVMETH (XDEVICE (c->device), finalize_color_instance, (c));
  99. }
  100.  
  101. static int
  102. color_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
  103. {
  104.   struct Lisp_Color_Instance *c1 = XCOLOR_INSTANCE (o1);
  105.   struct Lisp_Color_Instance *c2 = XCOLOR_INSTANCE (o2);
  106.   struct device *d1 = XDEVICE (c1->device);
  107.   struct device *d2 = XDEVICE (c2->device);
  108.  
  109.   if (d1 != d2)
  110.     return 0;
  111.  
  112.   if (!HAS_DEVMETH_P (d1, color_instance_equal))
  113.     return EQ (o1, o2);
  114.   return DEVMETH (d1, color_instance_equal, (c1, c2, depth));
  115. }
  116.  
  117. static unsigned long
  118. color_instance_hash (Lisp_Object obj, int depth)
  119. {
  120.   struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
  121.   struct device *d = XDEVICE (c->device);
  122.  
  123.   return HASH2 ((unsigned long) d,
  124.         DEVMETH_OR_GIVEN (d, color_instance_hash, (c, depth),
  125.                   LISP_HASH (obj)));
  126. }
  127.  
  128. DEFUN ("make-color-instance", Fmake_color_instance, Smake_color_instance,
  129.        1, 3, 0,
  130.        "Creates a new `color-instance' object of the specified color.\n\
  131. DEVICE specifies the device this object applies to and defaults to the\n\
  132. selected device.  An error is signalled if the color is unknown or cannot\n\
  133. be allocated; however, if NOERROR is non-nil, nil is simply returned in\n\
  134. this case.\n\
  135. \n\
  136. The returned object is a normal, first-class lisp object.  The way you\n\
  137. `deallocate' the color is the way you deallocate any other lisp object:\n\
  138. you drop all pointers to it and allow it to be garbage collected.  When\n\
  139. these objects are GCed, the underlying window-system data (e.g. X object)\n\
  140. is deallocated as well.")
  141.   (name, device, no_error)
  142.   Lisp_Object name, device, no_error;
  143. {
  144.   struct Lisp_Color_Instance *c;
  145.   Lisp_Object val;
  146.   int retval = 0;
  147.  
  148.   CHECK_STRING (name, 0);
  149.   XSETDEVICE (device, get_device (device));
  150.  
  151.   c = alloc_lcrecord (sizeof (struct Lisp_Color_Instance),
  152.               lrecord_color_instance);
  153.   c->name = name;
  154.   c->device = device;
  155.  
  156.   c->data = 0;
  157.  
  158.   retval = MAYBE_INT_DEVMETH (XDEVICE (device), initialize_color_instance,
  159.                   (c, name, device, !NILP (no_error)));
  160.  
  161.   if (!retval)
  162.     return Qnil;
  163.  
  164.   XSETCOLOR_INSTANCE (val, c);
  165.   return val;
  166. }
  167.  
  168. DEFUN ("color-instance-p", Fcolor_instance_p, Scolor_instance_p, 1, 1, 0,
  169.        "Return non-nil if OBJECT is a color instance.")
  170.   (object)
  171.   Lisp_Object object;
  172. {
  173.   return (COLOR_INSTANCEP (object) ? Qt : Qnil);
  174. }
  175.  
  176. DEFUN ("color-instance-name", Fcolor_instance_name, Scolor_instance_name,
  177.        1, 1, 0,
  178.        "Return the name used to allocate COLOR-INSTANCE.")
  179.   (color_instance)
  180.   Lisp_Object color_instance;
  181. {
  182.   CHECK_COLOR_INSTANCE (color_instance, 0);
  183.   return (XCOLOR_INSTANCE (color_instance)->name);
  184. }
  185.  
  186. DEFUN ("color-instance-rgb-components", Fcolor_instance_rgb_components,
  187.        Scolor_instance_rgb_components, 1, 1, 0,
  188.        "Return a three element list containing the red, green, and blue\n\
  189. color components of COLOR-INSTANCE, or nil if unknown.")
  190.      (color_instance)
  191.      Lisp_Object color_instance;
  192. {
  193.   struct Lisp_Color_Instance *c;
  194.  
  195.   CHECK_COLOR_INSTANCE (color_instance, 0);
  196.   c = XCOLOR_INSTANCE (color_instance);
  197.  
  198.   return MAYBE_LISP_DEVMETH (XDEVICE (c->device),
  199.                  color_instance_rgb_components,
  200.                  (c));
  201. }
  202.  
  203. DEFUN ("valid-color-name-p", Fvalid_color_name_p, Svalid_color_name_p,
  204.        1, 2, 0,
  205.        "Return true if COLOR names a valid color for the current device.\n\
  206. \n\
  207. Valid color names for X are listed in the file /usr/lib/X11/rgb.txt, or\n\
  208. whatever the equivalent is on your system.\n\
  209. \n\
  210. Valid color names for TTY are those which have an ISO 6429 (ANSI) sequence.\n\
  211. In addition to being a color this may be one of a number of attributes\n\
  212. such as `blink'.")
  213.      (color, device)
  214.      Lisp_Object color, device;
  215. {
  216.   struct device *d = get_device (device);
  217.  
  218.   CHECK_STRING (color, 0);
  219.   return MAYBE_INT_DEVMETH (d, valid_color_name_p, (d, color)) ? Qt : Qnil;
  220. }
  221.  
  222.  
  223. /***************************************************************************
  224.  *                       Font-Instance Object                              *
  225.  ***************************************************************************/
  226.  
  227. Lisp_Object Qfont_instancep;
  228. static Lisp_Object mark_font_instance (Lisp_Object, void (*) (Lisp_Object));
  229. static void print_font_instance (Lisp_Object, Lisp_Object, int);
  230. static void finalize_font_instance (void *, int);
  231. static int font_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth);
  232. static unsigned long font_instance_hash (Lisp_Object obj, int depth);
  233. DEFINE_LRECORD_IMPLEMENTATION ("font-instance", font_instance,
  234.                    mark_font_instance, print_font_instance,
  235.                    finalize_font_instance, font_instance_equal,
  236.                    font_instance_hash, struct Lisp_Font_Instance);
  237.  
  238. static Lisp_Object font_instance_truename_internal (Lisp_Object xfont,
  239.                             int no_error);
  240.  
  241. static Lisp_Object
  242. mark_font_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
  243. {
  244.   struct Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
  245.  
  246.   ((markobj) (f->name));
  247.   MAYBE_DEVMETH (XDEVICE (f->device), mark_font_instance, (f, markobj));
  248.  
  249.   return f->device;
  250. }
  251.  
  252. static void
  253. print_font_instance (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
  254. {
  255.   char buf[200];
  256.   struct Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
  257.   if (print_readably)
  258.     error ("printing unreadable object #<font-instance 0x%x>", f->header.uid);
  259.   write_c_string ("#<font-instance ", printcharfun);
  260.   print_internal (f->name, printcharfun, 0);
  261.   write_c_string (" on ", printcharfun);
  262.   print_internal (f->device, printcharfun, 0);
  263.   MAYBE_DEVMETH (XDEVICE (f->device), print_font_instance,
  264.          (f, printcharfun, escapeflag));
  265.   sprintf (buf, " 0x%x>", f->header.uid);
  266.   write_c_string (buf, printcharfun);
  267. }
  268.  
  269. static void
  270. finalize_font_instance (void *header, int for_disksave)
  271. {
  272.   struct Lisp_Font_Instance *f = (struct Lisp_Font_Instance *) header;
  273.   struct device *d = XDEVICE (f->device);
  274.  
  275.   if (for_disksave) finalose (f);
  276.  
  277.   MAYBE_DEVMETH (d, finalize_font_instance, (f));
  278. }
  279.  
  280. /* Fonts are equal if they resolve to the same name.
  281.    Since we call `font-truename' to do this, and since font-truename is lazy,
  282.    this means the `equal' could cause XListFonts to be run the first time.
  283.  */
  284. static int
  285. font_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
  286. {
  287.   /* #### should this be moved into a device method? */
  288.   return (internal_equal (font_instance_truename_internal (o1, 1),
  289.               font_instance_truename_internal (o2, 1),
  290.               depth + 1));
  291. }
  292.  
  293. static unsigned long
  294. font_instance_hash (Lisp_Object obj, int depth)
  295. {
  296.   return internal_hash (font_instance_truename_internal (obj, 1),
  297.             depth + 1);
  298. }
  299.  
  300. DEFUN ("make-font-instance", Fmake_font_instance, Smake_font_instance, 1, 3, 0,
  301.        "Creates a new `font-instance' object of the specified name.\n\
  302. DEVICE specifies the device this object applies to and defaults to the\n\
  303. selected device.  An error is signalled if the font is unknown or cannot\n\
  304. be allocated; however, if NOERROR is non-nil, nil is simply returned in\n\
  305. this case.\n\
  306. \n\
  307. The returned object is a normal, first-class lisp object.  The way you\n\
  308. `deallocate' the font is the way you deallocate any other lisp object:\n\
  309. you drop all pointers to it and allow it to be garbage collected.  When\n\
  310. these objects are GCed, the underlying X data is deallocated as well.")
  311.   (name, device, no_error)
  312.   Lisp_Object name, device, no_error;
  313. {
  314.   struct Lisp_Font_Instance *f;
  315.   Lisp_Object val;
  316.   int retval = 0;
  317.  
  318.   if (NILP (no_error))
  319.     CHECK_STRING (name, 0);
  320.   else if (!STRINGP (name))
  321.     return Qnil;
  322.  
  323.   XSETDEVICE (device, get_device (device));
  324.  
  325.   f = alloc_lcrecord (sizeof (struct Lisp_Font_Instance),
  326.               lrecord_font_instance);
  327.   f->name = name;
  328.   f->device = device;
  329.  
  330.   f->data = 0;
  331.  
  332.   retval = MAYBE_INT_DEVMETH (XDEVICE (device), initialize_font_instance,
  333.                   (f, name, device, !NILP (no_error)));
  334.  
  335.   if (!retval)
  336.     return Qnil;
  337.  
  338.   XSETFONT_INSTANCE (val, f);
  339.   return val;
  340. }
  341.  
  342. DEFUN ("font-instance-p", Ffont_instance_p, Sfont_instance_p, 1, 1, 0,
  343.        "Return non-nil if OBJECT is a font instance.")
  344.      (object)
  345.      Lisp_Object object;
  346. {
  347.   return (FONT_INSTANCEP (object) ? Qt : Qnil);
  348. }
  349.  
  350. DEFUN ("font-instance-name", Ffont_instance_name, Sfont_instance_name, 1, 1, 0,
  351.        "Return the name used to allocate FONT-INSTANCE.")
  352.      (font_instance)
  353.      Lisp_Object font_instance;
  354. {
  355.   CHECK_FONT_INSTANCE (font_instance, 0);
  356.   return (XFONT_INSTANCE (font_instance)->name);
  357. }
  358.  
  359. Lisp_Object
  360. font_instance_truename_internal (Lisp_Object font_instance, int no_error)
  361. {
  362.   struct Lisp_Font_Instance *f = XFONT_INSTANCE (font_instance);
  363.   return DEVMETH_OR_GIVEN (XDEVICE (f->device), font_instance_truename,
  364.                (f, no_error), f->name);
  365. }
  366.  
  367. DEFUN ("font-instance-truename", Ffont_instance_truename,
  368.        Sfont_instance_truename, 1, 1, 0,
  369.        "Return the canonical name of the given font instance.\n\
  370. Font names are patterns which may match any number of fonts, of which\n\
  371. the first found is used.  This returns an unambiguous name for that font\n\
  372. (but not necessarily its only unambiguous name).")
  373.   (font_instance)
  374.   Lisp_Object font_instance;
  375. {
  376.   CHECK_FONT_INSTANCE (font_instance, 0);
  377.   return font_instance_truename_internal (font_instance, 0);
  378. }
  379.  
  380. DEFUN ("font-instance-properties", Ffont_instance_properties,
  381.        Sfont_instance_properties, 1, 1, 0,
  382.    "Return the properties (an alist or nil) of FONT-INSTANCE.")
  383.   (font_instance)
  384.   Lisp_Object font_instance;
  385. {
  386.   struct Lisp_Font_Instance *f;
  387.  
  388.   CHECK_FONT_INSTANCE (font_instance, 0);
  389.   f = XFONT_INSTANCE (font_instance);
  390.  
  391.   return MAYBE_LISP_DEVMETH (XDEVICE (f->device),
  392.                  font_instance_properties, (f));
  393. }
  394.  
  395. DEFUN ("list-fonts", Flist_fonts, Slist_fonts, 1, 2, 0,
  396.        "Return a list of font names matching the given pattern.\n\
  397. DEVICE specifies which device to search for names, and defaults to the\n\
  398. currently selected device.")
  399.   (pattern, device)
  400.   Lisp_Object pattern, device;
  401. {
  402.   CHECK_STRING (pattern, 0);
  403.   XSETDEVICE (device, get_device (device));
  404.  
  405.   return MAYBE_LISP_DEVMETH (XDEVICE (device), list_fonts, (pattern, device));
  406. }
  407.  
  408.  
  409. /****************************************************************************
  410.  Color Object
  411.  ***************************************************************************/
  412. DEFINE_SPECIFIER_TYPE (color);
  413. /* Qcolor defined in general.c */
  414.  
  415. static void
  416. color_create (Lisp_Object obj)
  417. {
  418.   struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
  419.  
  420.   COLOR_SPECIFIER_FACE (color) = Qnil;
  421.   COLOR_SPECIFIER_FACE_PROPERTY (color) = Qnil;
  422. }
  423.  
  424. static void
  425. color_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
  426. {
  427.   struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
  428.  
  429.   ((markobj) (COLOR_SPECIFIER_FACE (color)));
  430.   ((markobj) (COLOR_SPECIFIER_FACE_PROPERTY (color)));
  431. }
  432.  
  433. /* No equal or hash methods; ignore the face the color is based off
  434.    of for `equal' */
  435.  
  436. static Lisp_Object
  437. color_instantiate (Lisp_Object specifier, Lisp_Object domain,
  438.            Lisp_Object instantiator, int no_error_or_quit)
  439. {
  440.   Lisp_Object device = DFW_DEVICE (domain);
  441.   struct device *d = XDEVICE (device);
  442.   Lisp_Object instance;
  443.  
  444.   if (COLOR_INSTANCEP (instantiator))
  445.     {
  446.       /* If we are on the same device then we're done.  Otherwise change
  447.          the instantiator to the name used to generate the pixel and let the
  448.          STRINGP case deal with it. */
  449.       if (EQ (device, XCOLOR_INSTANCE (instantiator)->device))
  450.     return instantiator;
  451.       else
  452.     instantiator = Fcolor_instance_name (instantiator);
  453.     }
  454.  
  455.   if (STRINGP (instantiator))
  456.     {
  457.       /* First, look to see if we can retrieve a cached value. */
  458.       instance = Fgethash (instantiator, d->color_instance_cache, Qnil);
  459.       /* Otherwise, make a new one. */
  460.       if (NILP (instance))
  461.     {
  462.       instance = Fmake_color_instance (instantiator, device, Qt);
  463.       if (NILP (instance))
  464.         return Qunbound; /* oops, couldn't allocate */
  465.       Fputhash (instantiator, instance, d->color_instance_cache);
  466.     }
  467.       return instance;
  468.     }
  469.   else if (CONSP (instantiator))
  470.     {
  471. #if 0
  472.       Lisp_Object *spec_list;
  473.       Lisp_Object ltmp;
  474.       int nargs = XINT (Flength (instantiator));
  475.       int cur_arg;
  476.  
  477.       /* This spec is only valid for tty devices.  If we get here and
  478.          the device is not a tty then there is a bug in the internal
  479.          color validation routines. */
  480.       if (!DEVICE_IS_TTY (d))
  481.     abort ();
  482.  
  483.       spec_list = (Lisp_Object *) xmalloc (sizeof (Lisp_Object) * nargs);
  484.       ltmp = instantiator;
  485.       cur_arg = 0;
  486.  
  487.       while (!NILP (ltmp))
  488.     {
  489.       Lisp_Object elt = XCAR (ltmp);
  490.       spec_list[cur_arg++] = elt;
  491.       ltmp = XCDR (ltmp);
  492.     }
  493.  
  494.       ltmp = Ftty_make_color_sequence (nargs, spec_list);
  495.       xfree (spec_list);
  496.       return ltmp;
  497. #endif
  498.       return Qunbound; /* #### do something about this. */
  499.     }
  500.   else if (VECTORP (instantiator))
  501.     {
  502.       /* #### Need loop detection. */
  503.       assert (XVECTOR (instantiator)->size == 2);
  504.       return (FACE_PROPERTY_INSTANCE
  505.           (Fget_face (vector_data (XVECTOR (instantiator))[0]),
  506.            vector_data (XVECTOR (instantiator))[1], domain, 0));
  507.     }
  508.   else if (NILP (instantiator))
  509.     return Qunbound;
  510.   else
  511.     abort ();    /* The spec validation routines are screwed up. */
  512.  
  513.   return Qunbound;
  514. }
  515.  
  516. static int
  517. color_validate (Lisp_Object instantiator, int no_error)
  518. {
  519.   /* #### signal some explanatory errors when NO_ERROR is nil */
  520.  
  521.   if (COLOR_INSTANCEP (instantiator) || STRINGP (instantiator) ||
  522.       NILP (instantiator))
  523.     return 1;
  524.   else if (VECTORP (instantiator) && XVECTOR (instantiator)->size == 2)
  525.     {
  526.       Lisp_Object face = vector_data (XVECTOR (instantiator))[0];
  527.       Lisp_Object field = vector_data (XVECTOR (instantiator))[1];
  528.       
  529.       if (SYMBOLP (face))
  530.     face = Ffind_face (face);
  531.       
  532.       if (!FACEP (face))
  533.     return 0;
  534.       else if (!EQ (field, Qforeground) && !EQ (field, Qbackground))
  535.     return 0;
  536.       
  537.       return 1;
  538.     }
  539.   else
  540.     return 0;
  541. }
  542.  
  543. static void
  544. color_after_change (Lisp_Object specifier, Lisp_Object locale)
  545. {
  546.   Lisp_Object face = COLOR_SPECIFIER_FACE (XCOLOR_SPECIFIER (specifier));
  547.   Lisp_Object property =
  548.     COLOR_SPECIFIER_FACE_PROPERTY (XCOLOR_SPECIFIER (specifier));
  549.   if (!NILP (face))
  550.     face_property_was_changed (face, property, locale);
  551. }
  552.  
  553. void
  554. set_color_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
  555. {
  556.   struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
  557.  
  558.   COLOR_SPECIFIER_FACE (color) = face;
  559.   COLOR_SPECIFIER_FACE_PROPERTY (color) = property;
  560. }
  561.  
  562. DEFUN ("color-specifier-p", Fcolor_specifier_p, Scolor_specifier_p, 1, 1, 0,
  563.        "Return non-nil if OBJECT is a color specifier.")
  564.      (object)
  565.      Lisp_Object object;
  566. {
  567.   return (COLOR_SPECIFIERP (object) ? Qt : Qnil);
  568. }
  569.  
  570.  
  571. /****************************************************************************
  572.  Font Object
  573.  ***************************************************************************/
  574. DEFINE_SPECIFIER_TYPE (font);
  575. /* Qfont defined in general.c */
  576.  
  577. static void
  578. font_create (Lisp_Object obj)
  579. {
  580.   struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
  581.  
  582.   FONT_SPECIFIER_FACE (font) = Qnil;
  583.   FONT_SPECIFIER_FACE_PROPERTY (font) = Qnil;
  584. }
  585.  
  586. static void
  587. font_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
  588. {
  589.   struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
  590.  
  591.   ((markobj) (FONT_SPECIFIER_FACE (font)));
  592.   ((markobj) (FONT_SPECIFIER_FACE_PROPERTY (font)));
  593. }
  594.  
  595. /* No equal or hash methods; ignore the face the font is based off
  596.    of for `equal' */
  597.  
  598. static Lisp_Object
  599. font_instantiate (Lisp_Object specifier, Lisp_Object domain,
  600.           Lisp_Object instantiator, int no_error_or_quit)
  601. {
  602.   Lisp_Object device = DFW_DEVICE (domain);
  603.   struct device *d = XDEVICE (device);
  604.   Lisp_Object instance;
  605.  
  606.   if (FONT_INSTANCEP (instantiator))
  607.     {
  608.       if (EQ (device, XFONT_INSTANCE (instantiator)->device))
  609.     return instantiator;
  610.       else
  611.     instantiator = Ffont_instance_name (instantiator);
  612.     }
  613.   else if (STRINGP (instantiator))
  614.     {
  615.       /* First, look to see if we can retrieve a cached value. */
  616.       instance = Fgethash (instantiator, d->font_instance_cache, Qnil);
  617.       /* Otherwise, make a new one. */
  618.       if (NILP (instance))
  619.     {
  620.       instance = Fmake_font_instance (instantiator, device, Qt);
  621.       if (NILP (instance))
  622.         return Qunbound; /* oops, couldn't allocate */
  623.       Fputhash (instantiator, instance, d->font_instance_cache);
  624.     }
  625.       return instance;
  626.     }
  627.   else if (VECTORP (instantiator))
  628.     {
  629.       /* #### Need loop detection. */
  630.       assert (XVECTOR (instantiator)->size == 1);
  631.       return (FACE_FONT
  632.           (Fget_face (vector_data (XVECTOR (instantiator))[0]), domain));
  633.     }
  634.   else if (NILP (instantiator))
  635.     return Qunbound;
  636.   else
  637.     abort ();    /* Eh? */
  638.  
  639.   return Qunbound;
  640. }
  641.  
  642. static int
  643. font_validate (Lisp_Object instantiator, int no_error)
  644. {
  645.   /* #### signal some explanatory errors when CAN_SIGNAL_ERROR is t */
  646.  
  647.   if (FONT_INSTANCEP (instantiator) || STRINGP (instantiator) ||
  648.       NILP (instantiator))
  649.     return 1;
  650.   else if (VECTORP (instantiator) && XVECTOR (instantiator)->size == 1)
  651.     {
  652.       Lisp_Object face = vector_data (XVECTOR (instantiator))[0];
  653.       
  654.       if (SYMBOLP (face))
  655.     face = Ffind_face (face);
  656.       
  657.       if (!FACEP (face))
  658.     return 0;
  659.       
  660.       return 1;
  661.     }
  662.   else
  663.     return 0;
  664. }
  665.  
  666. static void
  667. font_after_change (Lisp_Object specifier, Lisp_Object locale)
  668. {
  669.   Lisp_Object face = FONT_SPECIFIER_FACE (XFONT_SPECIFIER (specifier));
  670.   Lisp_Object property =
  671.     FONT_SPECIFIER_FACE_PROPERTY (XFONT_SPECIFIER (specifier));
  672.   if (!NILP (face))
  673.     face_property_was_changed (face, property, locale);
  674. }
  675.  
  676. void
  677. set_font_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
  678. {
  679.   struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
  680.  
  681.   FONT_SPECIFIER_FACE (font) = face;
  682.   FONT_SPECIFIER_FACE_PROPERTY (font) = property;
  683. }
  684.  
  685. DEFUN ("font-specifier-p", Ffont_specifier_p, Sfont_specifier_p, 1, 1, 0,
  686.        "Return non-nil if OBJECT is a font specifier.")
  687.      (object)
  688.      Lisp_Object object;
  689. {
  690.   return (FONT_SPECIFIERP (object) ? Qt : Qnil);
  691. }
  692.  
  693.  
  694. /*****************************************************************************
  695.  Face Boolean Object
  696.  ****************************************************************************/
  697. DEFINE_SPECIFIER_TYPE (face_boolean);
  698. Lisp_Object Qface_boolean;
  699.  
  700. static void
  701. face_boolean_create (Lisp_Object obj)
  702. {
  703.   struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
  704.  
  705.   FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = Qnil;
  706.   FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = Qnil;
  707. }
  708.  
  709. static void
  710. face_boolean_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
  711. {
  712.   struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
  713.  
  714.   ((markobj) (FACE_BOOLEAN_SPECIFIER_FACE (face_boolean)));
  715.   ((markobj) (FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean)));
  716. }
  717.  
  718. /* No equal or hash methods; ignore the face the face-boolean is based off
  719.    of for `equal' */
  720.  
  721. static Lisp_Object
  722. face_boolean_instantiate (Lisp_Object specifier, Lisp_Object domain,
  723.               Lisp_Object instantiator, int no_error_or_quit)
  724. {
  725.   /* #### signal some explanatory errors when CAN_SIGNAL_ERROR is t */
  726.  
  727.   if (NILP (instantiator) || EQ (instantiator, Qt))
  728.     return instantiator;
  729.   else if (VECTORP (instantiator))
  730.     {
  731.       Lisp_Object retval;
  732.  
  733.       assert (XVECTOR (instantiator)->size == 2 ||
  734.           XVECTOR (instantiator)->size == 3);
  735.       retval = FACE_PROPERTY_INSTANCE
  736.     (Fget_face (vector_data (XVECTOR (instantiator))[0]),
  737.      vector_data (XVECTOR (instantiator))[1], domain, 0);
  738.  
  739.       if (XVECTOR (instantiator)->size == 3 &&
  740.       !NILP (vector_data (XVECTOR (instantiator))[2]))
  741.     retval = (NILP (retval) ? Qt : Qnil);
  742.  
  743.       return instantiator;
  744.     }
  745.   else
  746.     abort ();    /* Eh? */
  747.  
  748.   return Qunbound;
  749. }
  750.  
  751. static int
  752. face_boolean_validate (Lisp_Object instantiator, int no_error)
  753. {
  754.   if (NILP (instantiator) || EQ (instantiator, Qt))
  755.     return 1;
  756.   else if (VECTORP (instantiator) &&
  757.        (XVECTOR (instantiator)->size == 2 ||
  758.         XVECTOR (instantiator)->size == 3))
  759.     {
  760.       Lisp_Object face = vector_data (XVECTOR (instantiator))[0];
  761.       Lisp_Object field = vector_data (XVECTOR (instantiator))[1];
  762.       
  763.       if (SYMBOLP (face))
  764.     face = Ffind_face (face);
  765.       
  766.       if (!FACEP (face))
  767.     return 0;
  768.       else if (!EQ (field, Qunderline)
  769.            && !EQ (field, Qhighlight)
  770.            && !EQ (field, Qdim)
  771.            && !EQ (field, Qblinking)
  772.            && !EQ (field, Qreverse))
  773.     return 0;
  774.  
  775.       return 1;
  776.     }
  777.   else
  778.     return 0;
  779. }
  780.  
  781. static void
  782. face_boolean_after_change (Lisp_Object specifier, Lisp_Object locale)
  783. {
  784.   Lisp_Object face =
  785.     FACE_BOOLEAN_SPECIFIER_FACE (XFACE_BOOLEAN_SPECIFIER (specifier));
  786.   Lisp_Object property =
  787.     FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (XFACE_BOOLEAN_SPECIFIER (specifier));
  788.   if (!NILP (face))
  789.     face_property_was_changed (face, property, locale);
  790. }
  791.  
  792. void
  793. set_face_boolean_attached_to (Lisp_Object obj, Lisp_Object face,
  794.                   Lisp_Object property)
  795. {
  796.   struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
  797.  
  798.   FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = face;
  799.   FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = property;
  800. }
  801.  
  802. DEFUN ("face-boolean-specifier-p", Fface_boolean_specifier_p,
  803.        Sface_boolean_specifier_p, 1, 1, 0,
  804.        "Return non-nil if OBJECT is a face-boolean specifier.")
  805.      (object)
  806.      Lisp_Object object;
  807. {
  808.   return (FACE_BOOLEAN_SPECIFIERP (object) ? Qt : Qnil);
  809. }
  810.  
  811.  
  812. /************************************************************************/
  813. /*                            initialization                            */
  814. /************************************************************************/
  815.  
  816. void
  817. syms_of_objects (void)
  818. {
  819.   defsubr (&Scolor_specifier_p);
  820.   defsubr (&Sfont_specifier_p);
  821.   defsubr (&Sface_boolean_specifier_p);
  822.  
  823.   defsymbol (&Qcolor_instancep, "color-instance-p");
  824.   defsubr (&Smake_color_instance);
  825.   defsubr (&Scolor_instance_p);
  826.   defsubr (&Scolor_instance_name);
  827.   defsubr (&Scolor_instance_rgb_components);
  828.   defsubr (&Svalid_color_name_p);
  829.  
  830.   defsymbol (&Qfont_instancep, "font-instance-p");
  831.   defsubr (&Smake_font_instance);
  832.   defsubr (&Sfont_instance_p);
  833.   defsubr (&Sfont_instance_name);
  834.   defsubr (&Sfont_instance_truename);
  835.   defsubr (&Sfont_instance_properties);
  836.   defsubr (&Slist_fonts);
  837.  
  838.   /* Qcolor, Qfont defined in general.c */
  839.   defsymbol (&Qface_boolean, "face-boolean");
  840. }
  841.  
  842. void
  843. specifier_type_create_objects (void)
  844. {
  845.   INITIALIZE_SPECIFIER_TYPE_WITH_DATA (color, "color", "color-specifier-p");
  846.   INITIALIZE_SPECIFIER_TYPE_WITH_DATA (font, "font", "font-specifier-p");
  847.   INITIALIZE_SPECIFIER_TYPE_WITH_DATA (face_boolean, "face-boolean",
  848.                      "face-boolean-specifier-p");
  849.  
  850.   SPECIFIER_HAS_METHOD (color, instantiate);
  851.   SPECIFIER_HAS_METHOD (font, instantiate);
  852.   SPECIFIER_HAS_METHOD (face_boolean, instantiate);
  853.  
  854.   SPECIFIER_HAS_METHOD (color, validate);
  855.   SPECIFIER_HAS_METHOD (font, validate);
  856.   SPECIFIER_HAS_METHOD (face_boolean, validate);
  857.  
  858.   SPECIFIER_HAS_METHOD (color, create);
  859.   SPECIFIER_HAS_METHOD (font, create);
  860.   SPECIFIER_HAS_METHOD (face_boolean, create);
  861.  
  862.   SPECIFIER_HAS_METHOD (color, mark);
  863.   SPECIFIER_HAS_METHOD (font, mark);
  864.   SPECIFIER_HAS_METHOD (face_boolean, mark);
  865.  
  866.   SPECIFIER_HAS_METHOD (color, after_change);
  867.   SPECIFIER_HAS_METHOD (font, after_change);
  868.   SPECIFIER_HAS_METHOD (face_boolean, after_change);
  869. }
  870.